83B - Doctor - CodeForces Solution


binary search math sortings *1800

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>



#define pb push_back

#define rep(i,a,b) for( int i = a; i < b; i++ )

#define debug(a) cout << #a << " = " << a << endl;

#define debug2(a,b) cout << #a << " = " << a << " --- " << #b << " = " << b << endl;



using namespace std;



typedef long long int ll;



int main(){

	ll n, k, t[100100], sum = 0;

	

	scanf("%I64d%I64d", &n, &k );

	rep( i, 0, n ){

		scanf("%I64d", &t[i] );

		sum += t[i];

	}

	

	if( sum < k ){

		puts("-1");

		return 0;

	}

	ll lo = 1, hi = 1e9, mid, x;

	while( lo <= hi ){

		mid = (lo+hi)/2;

		sum = 0;

		rep( i, 0, n ) sum += min( t[i], mid );

		if( sum > k ) hi = mid-1;

		else{

			x = mid;

			lo = mid+1;

		}

	}

	

	rep( i, 0, n ){

		k -= min( t[i], x );

		t[i] -= x;

	}

	int p;

	for( p = 0; k; p++ ){

		if( t[p] > 0 ) k--, t[p]--;

	}

	rep( i, p, n ) if( t[i] > 0 ) printf("%d ", i+1 );

	rep( i, 0, p ) if( t[i] > 0 ) printf("%d ", i+1 );

	printf("\n");

}




Comments

Submit
0 Comments
More Questions

340A - The Wall
377A - Maze
500A - New Year Transportation
908D - New Year and Arbitrary Arrangement
199A - Hexadecimal's theorem
519C - A and B and Team Training
631A - Interview
961B - Lecture Sleep
522A - Reposts
1166D - Cute Sequences
1176A - Divide it
1527A - And Then There Were K
1618E - Singers' Tour
1560B - Who's Opposite
182B - Vasya's Calendar
934A - A Compatible Pair
1618F - Reverse
1684C - Column Swapping
57C - Array
1713D - Tournament Countdown
33A - What is for dinner
810A - Straight A
1433C - Dominant Piranha
633A - Ebony and Ivory
1196A - Three Piles of Candies
299A - Ksusha and Array
448B - Suffix Structures
1092B - Teams Forming
1166C - A Tale of Two Lands
544B - Sea and Islands